using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class testcase_categories : System.Web.UI.Page
{
    SQLInteract objSQL = new SQLInteract();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["UnchkID"] != null)
            {
                hdnid.Value = Session["UnchkID"].ToString().Trim();
            }
            string strgrp = Request.QueryString["GrpID"].ToString();
            if (Request.QueryString["GrpID"].ToString().Trim() != null || Request.QueryString["GrpID"].ToString().Trim() != string.Empty)
            {
                string grpName = "";
                int Grpid = int.Parse(Request.QueryString["GrpID"]);
                
                try
                {
                    grpName = (string)objSQL.sqlExecuteScalar("Select distinct Group_Name from CollectionScenarios_TB_Generic where Group_Order='" + Grpid + "' and FlowType='" + Session["FlowType"].ToString().Trim() + "'");
                }
                catch(Exception ex)
                {
                    this.ClientScript.RegisterStartupScript(this.Page.GetType(), "Alert", "<script language=\"javascript\" type=\"text/javascript\" >alert(\"Error: " + ex.Message + "\");</script>", false);
                }
                Page.Title = grpName;
                lblCatName.Text = grpName;
                DisplayCheckBoxes(Grpid, grpName);
            }
            else
            {
                lblStatus.Text = "No entry found for Selected Group.";
            }
        }
    }

    void DisplayCheckBoxes(int grpID,string grpNm)
    {
        Table DynTable = new Table();
        DataSet CheckItemsDta = new DataSet();
        try
        {
            CheckItemsDta = objSQL.ReturnDataAdapter("Select Index_Num,Action_Name from CollectionScenarios_TB_Generic where Group_Name='" + grpNm.ToString().Trim() + "' and Group_Order=" + grpID + " and FlowType='" + Session["FlowType"].ToString().Trim() + "' order by Index_Num");
            if (CheckItemsDta.Tables.Count > 0)
            {
                foreach (DataRow row in CheckItemsDta.Tables[0].Rows)
                {
                    ListItem lstItmCat = new ListItem();
                    lstItmCat.Text = row["Action_Name"].ToString();
                    lstItmCat.Value = row["Index_Num"].ToString();
                    BulletedList blcat = new BulletedList();
                    blcat.BulletStyle=BulletStyle.CustomImage;
                    blcat.BulletImageUrl="Images/SymbolCheck.png";
                    blcat.Items.Add(lstItmCat);
                    pnlActions.Controls.Add(blcat);
                }                
            }
        }
        catch (Exception ex)
        {
            CheckItemsDta.Dispose();
            this.ClientScript.RegisterStartupScript(this.Page.GetType(), "Alert", "<script language=\"javascript\" type=\"text/javascript\" >alert(\"Error: " + ex.Message + "\");</script>", false);
        }
        finally
        {
            CheckItemsDta.Dispose();
        }
    }
}
